<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>

/* 练习 请尝试用filter()筛选出素数： */

'use strict';

function get_primes(arr) {
    return arr.filter(function(r){
        let isShu=true;
        if(r===1){
           return false;
        }
        for(let i=2;i<r;i++){
            if(r%i===0){
                isShu=false;
                return isShu
            }

        }
        return isShu;
    });

}

// 测试:
var
    x,
    r,
    arr = [];
for (x = 1; x < 100; x++) {
    arr.push(x);
}
r = get_primes(arr);
if (r.toString() === [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97].toString()) {
    console.log('测试通过!');
} else {
    console.log('测试失败: ' + r.toString());
}




</script>

<script src="./a.js"></script>
</body>
</html>